package com.a3dweijing.wetouch2.Util;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.base.App;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;


/**
 * author : YXD
 * Created on 2017/3/30.
 */
public class ImageLoaderUtil {

    private static ImageLoaderUtil instance;
    private static DisplayImageOptions options;
    private static DisplayImageOptions options2;
    private static ImageLoader loader;
    private static String head="http://wetouch.oss-cn-hangzhou.aliyuncs.com/";
    private static String head2="http://yiletech.oss-cn-shenzhen.aliyuncs.com/";
//    private static String head="http://video.3dweijing.com/";
    private static String foot="?x-oss-process=style/img_lay";

    private ImageLoaderUtil() {
    }
    static {
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.timg)
                .cacheInMemory(true).cacheOnDisc(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
    }
    public static ImageLoaderUtil getLoader(){
        if (instance==null) {
            loader= ImageLoader.getInstance();
            loader.init(ImageLoaderConfiguration.createDefault(App.getmContext()));
            instance=new ImageLoaderUtil();
        }
        return instance;
    }

    public void loadImg(String url, ImageView imageView){
        loader.displayImage(head+url+foot,imageView, options);
    }

    public void loadImg2(String url, ImageView imageView){
        loader.displayImage(url,imageView, options);
    }
    public void loadImg3(String url, ImageView imageView){
        options2 = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.timg)
                .showImageOnFail(R.drawable.timg)
                .cacheInMemory(true).cacheOnDisc(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        loader.displayImage(head+url+foot,imageView, options2);
    }
    public void loadImg4(String url, ImageView imageView){
        if (url!=null){
            if(url.startsWith("http")){
                loadImg2(url,imageView);
            }else if (url.startsWith("wetouch")){
                loadImg(url,imageView);
            }else if (url.startsWith("upload")){
                loadImg2(head2+url,imageView);
            }else
            {
                loadImg2("http://oss.3dweijing.com/upload/"+url+foot,imageView);
            }
        }
    }

}
